package com.gdcirrus.fs.highway.network.${package}.service.test;

import com.cys.exam.interfaces.entity.${package}.I${entityName};
import com.cys.exam.interfaces.service.${package}.${entityName}Service;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import javax.annotation.Resource;


/**
 *  ${entityComment} Service单元测试
 *  @author ${author}
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring.xml")
public class ${entityName}ServiceImplTest{
	
	private static Logger logger = LoggerFactory.getLogger(${entityName}ServiceImplTest.class);
	
	@Resource(name="${entityNameSmall}ServiceImpl")
    private ${entityName}Service ${entityNameSmall}Service;
	
	/**
	 *	新增${entityName}
	 */
	@Test
    public void save() throws Exception {
    	System.out.println("进入新增方法");
    	Map<String,Object> param = new HashMap<>();
<#list dataList as var>    	
	<#if var.dataType == 'String'>
		param.put("${var.newColumn}","testString");
	</#if>
	<#if var.dataType == 'Integer'>
		param.put("${var.newColumn}","1");			
	</#if>
	<#if var.dataType == 'Long'>
		param.put("${var.newColumn}","1");
	</#if>
	<#if var.dataType == 'Date'>
		param.put("${var.newColumn}",new Date());					
	</#if>
	<#if var.dataType == 'Float'>
		param.put("${var.newColumn}","1.264");					
 	</#if>
</#list>    	
		I${entityName} ${entityNameSmall} = ${entityNameSmall}Service.save(param);
    	System.out.println("新增返回实体类 "+${entityNameSmall}.toString());
    }
    
	/**
	 *	修改${entityName}
	 */
	@Test
	public void update() throws Exception {
		System.out.println("进入修改方法");
		Map<String,Object> param = new HashMap<>();
<#list dataList as var>
	<#if var_index == 0>
	</#if>
	<#if var.dataType == 'String'>
		param.put("${var.newColumn}","aaasss");				
	</#if>
	<#if var.dataType == 'Integer'>
		param.put("${var.newColumn}","2");			
	</#if>
	<#if var.dataType == 'Long' && var_index != 0>
		param.put("${var.newColumn}","33211");					
	</#if>
	<#if var.dataType == 'Date'>
		param.put("${var.newColumn}",new Date());					
	</#if>
	<#if var.dataType == 'Float'>
		param.put("${var.newColumn}","2.3214");					
 	</#if>
</#list>		
		I${entityName} ${entityNameSmall} = ${entityNameSmall}Service.update(param);
    	System.out.println("修改返回实体类 "+${entityNameSmall}.toString());
	}

	/**
	 *  根据id获取${entityName}数据
	 */
	@Test
	public void findEntityById(){
		System.out.println("method[findEntityById] start");
		I${entityName} ${entityNameSmall} = ${entityNameSmall}Service.findEntityById(1L);
		System.out.println("method[findEntityById] end ${entityNameSmall}:"+${entityNameSmall}.toString());
    }

	/**
	 *  获取${entityName}列表数据
	 */
	@Test
	public void getList(){
		System.out.println("进入获取列表方法");
		Map<String,Object> map = new HashMap<>();
		List<I${entityName}> dataList = ${entityNameSmall}Service.findList(map);
		System.out.println("列表Size: "+dataList.size());
	}
	
	
	/**
	 *  通过id物理删除${entityName}
	 */
	@Test
	public void deleteById(){
		System.out.println("进入删除方法");
		${entityNameSmall}Service.deleteById(1L);
    	System.out.println("删除成功！");
	}
	
	/**
	 * 批量删除${entityName}
	 */
	@Test
	public void deleteBatch(){
		System.out.println("进入删除方法");
		Long[] ids = new Long[3];
		ids[0] = 1L;
		ids[1] = 2L;
		ids[2] = 3L;
		${entityNameSmall}Service.deleteBatch(ids);
		System.out.println("删除成功！");
	}

    /**
     * 获取分页列表
     */
    @Test
    public void pageList() {
		System.out.println("进入分页方法");
		Map<String, Object> map = new HashMap<>();
		PageInfo<I${entityName}> pageList = ${entityNameSmall}Service.findPage(1, 5, map);
        System.out.println("获取分页数据成功！ pageList.Total:" + pageList.getTotal());
	}
	
}
 



